/-editor
/-files
/-imports
/-layout
/-typings
TypeScriptService.ts
ko.ts
persistence.ts
shell.ts
teapo.html
teapo.js
teapo.ts
722
            script.setAttribute(row.name, row.value || '')
723
          else
724
            script.innerHTML = encodeForInnerHTML(row.value);
725
        }
726
 
727
        completed();
728
      });
729
  }
730
 
731
  function removeAttributes(element: HTMLElement) {
732
    for (var i = 0; i < element.attributes.length; i++) {
733
      var a = element.attributes[i];
734
      if (a.name === 'id' || a.name === 'type' || a.name === 'data-path')
735
        continue;
736
      element.removeAttribute(a.name);
737
      i--;
738
    }
739
  }
740
 
741
  /**
742
   * Escape unsafe character sequences like a closing script tag.
743
   */
744
  export function encodeForInnerHTML(content: string): string {
745
    // matching script closing tag with *one* or more consequtive slashes
746
    return content.replace(/<\/+script/g, (match) => {
747
      return '</' + match.slice(1); // skip angle bracket, inject bracket and extra slash
748
    });
749
  }
750
 
751
  /**
752
   * Unescape character sequences wrapped with encodeForInnerHTML for safety.
753
   */
754
  export function decodeFromInnerHTML(innerHTML: string): string {
755
    // matching script closing tag with *t*wo or more consequtive slashes
756
    return innerHTML.replace(/<\/\/+script/g, (match) => {
757
      return '<' + match.slice(2); // skip angle bracket and one slash, inject bracket
758
    });
759
  }
760
}